using System;
using System.Configuration;
using System.Globalization;

namespace Sustainalytics.Utils
{
    public class SyncHelper
    {
        public static int ReadCommandTimeOutFromConfig()
        {
            var commandTimeout = 60 * 60;
 
            if (ConfigurationManager.AppSettings["CommandTimeout"] != null)
                    commandTimeout = 60 * Convert.ToInt32(ConfigurationManager.AppSettings["CommandTimeout"]);

            return commandTimeout;      
        }
        

        public static DateTime? ReadControversiesChangedSinceFromConfig()
        {
            DateTime? changedSince = null;

            try
            {
                if (ConfigurationManager.AppSettings["ControversiesChangedSince"] != null)
                    changedSince = DateTime.Parse(ConfigurationManager.AppSettings["ControversiesChangedSince"], CultureInfo.CreateSpecificCulture("en-US"));
            }
            catch
            {
                //supress exception
            }

            return changedSince;
        }

        public static bool ReadIsControversiesInitialSyncFromConfig()
        {
            var isInitialSync = true;

            if (ConfigurationManager.AppSettings["IsControversiesInitialSync"] != null)
              isInitialSync = bool.Parse(ConfigurationManager.AppSettings["IsControversiesInitialSync"]);

            return isInitialSync;
        }
    }
}
